package org.one.afternoon.mock;

import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.extern.slf4j.Slf4j;
import org.one.afternoon.domain.JobDetails;
import org.one.afternoon.domain.TriggerDetails;
import org.one.afternoon.quartz.PersistToDs;
import org.one.afternoon.service.JobService;
import org.one.afternoon.service.TriggerService;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;

@PersistJobDataAfterExecution //持久化
@DisallowConcurrentExecution //禁止并发任务
@Component
@Slf4j
public class MockSignJob extends QuartzJobBean {

    @Autowired
    private JobService jobService;

    @Autowired
    private TriggerService triggerService;

    /**
     * 定时请求外部接口customers_sign接口
     * @param context Job本身的明细数据 Quartz运行时的环境
     * @throws JobExecutionException
     */
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            Thread.sleep(2000);
            log.info(context.getScheduler().getSchedulerInstanceId());
            log.info("taskName:"+context.getJobDetail().getKey().getName());
            log.info("time:"+new Date());
            log.info("SignJob is running...");
            for (int i = 0; i < context.getJobDetail().getJobDataMap().size(); i++) {
                log.info("签名"+i+":"+RandomValue.getCustomersSign());
            }
//            PersistToDs.addJob(context,jobService,triggerService);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
